package com.example.chuntiao.cophook.ui;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.chuntiao.cophook.R;

/**
 * Created by chuntiao on 17-8-30.
 */

public class BottomDialog extends Dialog {
    Context mContext;
    private View rootView;


    /**
     * 这是设置了各种属性的对话框，作为底部弹出框使用
     * 可以根据布局资源文件来定制
     * @param context
     * @param resource    布局资源文件id*/
    public BottomDialog(@NonNull Context context, @LayoutRes int resource) {

        super(context,R.style.BottomDialog);
        mContext=context;
        rootView=LayoutInflater.from(mContext).inflate(resource, null);


        setContentView(rootView);
        ViewGroup.LayoutParams layoutParams = rootView.getLayoutParams();
        layoutParams.width = mContext.getResources().getDisplayMetrics().widthPixels;
        rootView.setLayoutParams(layoutParams);

        getWindow().setGravity(Gravity.BOTTOM);
        getWindow().setWindowAnimations(R.style.BottomDialog_Animation);
        super.setCanceledOnTouchOutside(true);
    }

    /**
     * @return 返回此对话框所有控件的父控件,以便定制各种属性*/
    public View getRootView() {
        return rootView;
    }
}
